import java.util.List;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-05-04
 * Time: 13:58
 */
class Solution {
    public int minOperations(int[] nums) {
        int ans =0;
        int prev = nums[0];
        for(int i =1;i<nums.length;++i) {
            if(nums[i]>prev) {
                prev = nums[i];
            }else {
                ans+=(prev+1)-nums[i];
                prev++;
            }
        }
        return ans;
    }
}



class Solution1 {
    public int[] constructArr(int[] a) {
        if(a.length==0||a==null) {
            return new int[0];
        }
        int[] left = new int[a.length];
        int[] right = new int[a.length];
        left[0]=1;
        right[a.length-1] = 1;
        //填充左边
        for(int i =1;i<a.length;++i) {
            left[i] = left[i-1]*a[i-1];
        }
        //填充右边元素
        for(int j =a.length-2;j>=0;--j) {
            right[j] = right[j+1]*a[j+1];
        }
        for(int i =0;i<a.length;++i) {
            a[i] = left[i]*right[i];
        }
        return a;
    }
}

public class TestDemo {

    public static void main(String[] args) {
        Solution1 solution1 = new Solution1();
        int[] a= {1,2,3,4,5};
        solution1.constructArr(a);
    }

    public static void main2(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1,1,1};
        int ret = solution.minOperations(nums);
        System.out.println(ret);
    }

    public static void main1(String[] args) {
        Stack<Character> stack = new Stack<>();
        stack.push('a');
        stack.push('b');
        stack.push('b');
        stack.push('b');
        stack.push('b');
        System.out.println(stack);
        stack.pop();
        System.out.println(stack);
        System.out.println(stack.peek());
        System.out.println(stack);
    }

}
